package io.renren.modules.back.controller;

import io.renren.common.annotation.SysLog;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.common.validator.group.AddGroup;
import io.renren.modules.back.entity.AdPositionEntity;
import io.renren.modules.back.service.AdPositionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 广告位api
 *
 * @author zzh
 * @email 862583291@qq.com
 * @date 2019年5月11日 上午10:40:10
 */
@RestController
@RequestMapping("/back/adPosition")
public class AdPositionController {
    @Autowired
    private AdPositionService adPositionService;

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll() {
        List<AdPositionEntity> list = adPositionService.list();
        return R.ok().put("data", list);
    }




    /**
     * 查看列表
     */
    @GetMapping("/list")
    @RequiresPermissions("adPosition:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = adPositionService.queryPage(params);
        return R.ok().put("data", page);
    }

    /**
     * 查看信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("adPosition:info")
    public R info(@PathVariable("id") Long id){
        AdPositionEntity adPosition = adPositionService.getById(id);
        return R.ok().put("data", adPosition);
    }

    /**
     * 保存
     */
    @SysLog("保存广告位")
    @PostMapping("/save")
    @RequiresPermissions("adPosition:save")
    public R save(@RequestBody AdPositionEntity adPositionEntity){
        ValidatorUtils.validateEntity(adPositionEntity,AddGroup.class);
        adPositionService.save(adPositionEntity);
        return R.ok();
    }

    /**
     * 修改
     */
    @SysLog("修改广告位")
    @PostMapping("/update")
    @RequiresPermissions("adPosition:update")
    public R update(@RequestBody AdPositionEntity adPositionEntity){
        adPositionService.updateById(adPositionEntity);
        return R.ok();
    }

    /**
     * 删除
     */
    @SysLog("删除广告位")
    @PostMapping("/delete")
    @RequiresPermissions("adPosition:delete")
    public R delete(@RequestBody Long[] ids){
        adPositionService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }
}
